package com.leapp.sk.viewdelegate.leave

import android.content.Context
import android.support.v4.content.ContextCompat
import android.support.v4.widget.SwipeRefreshLayout
import android.text.TextUtils
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.RefreshListView
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.bean.LevelEntity
import com.leapp.sk.ui.activity.leave.LevelActivity
import com.leapp.sk.ui.adapter.LevelAdapter

/**
 * 请假
 * @author  chaohaipeng  on 2018/8/4.
 */
class LevelDelegate : BaseAppDelegate(){
    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_level
    }

    /**
     * 初始化适配器
     */
    fun initAdapter(context: Context, mlist: List<LevelEntity>, listener: SwipeRefreshLayout.OnRefreshListener){
        val lv_al_list = getView<RefreshListView>(R.id.lv_al_list)
        val srl_al_swipe = getView<SwipeRefreshLayout>(R.id.srl_al_swipe)
        val levelAdapter = LevelAdapter(getActivity(), mlist)
        lv_al_list.adapter=levelAdapter
        srl_al_swipe.setOnRefreshListener(listener)
        srl_al_swipe.setColorSchemeColors(ContextCompat.getColor(context, R.color.color_FF5894))
    }

    /**
     * 停止刷新
     */
    fun stopSwipRefresh(){
        val srl_al_swipe = getView<SwipeRefreshLayout>(R.id.srl_al_swipe)
        srl_al_swipe.isRefreshing=false
    }

    /**
     * 设置标题
     */
    fun setTitle(title:String?){
        val topBar= getView<SKTopBar>(R.id.jtb_al)
        if (!TextUtils.isEmpty(title)){
            topBar?.setTitle(title)
        }
        setEvent(topBar)
    }
    /**
     * 设置设置事件
     */
    private  fun setEvent(topBar: SKTopBar){
        topBar?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<LevelActivity>().finish()

            }
            override fun rightOnClick() {
            }

        })
    }


}